package com.wdz.service.impl;

import com.wdz.currency_query.service.CurrencyQueryService;
import com.wdz.currency_query.utils.Param;
import com.wdz.entity.ApiUser;
import com.wdz.service.IApiUserService;
import com.wdz.utils.PageUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ApiUserServiceImpl implements IApiUserService {

    private CurrencyQueryService currencyQueryService = new CurrencyQueryService();

    @Override
    public ApiUser queryApiUser(String username) {
        Param param = new Param();
        param.keywords = param.new Keywords();
        param.keywords.setK_type(3);
        param.keywords.setK_cloum("admin_name");
        param.keywords.setK_value(username);
        PageUtil pageUtil = currencyQueryService.searchCurr("admin",param);
        List<Map<String, Object>> admins = (List<Map<String, Object>>) pageUtil.getData();
        Map<String, Object> admin = admins.get(0);
        ApiUser apiUser = new ApiUser();
        apiUser.setUsername((String) admin.get("adminName"));
        apiUser.setPassword((String) admin.get("password"));
        //先定死为2即正常用户
        apiUser.setEnable(2);
        apiUser.setAuthorities((String) admin.get("authorities"));
        return apiUser;
    }
}
